import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:top_foundation/component/component.dart';
import 'package:top_foundation/component/page_state/widgets/empty.dart';
import 'package:whale/helper/utils/color.dart';
import 'package:whale/helper/utils/util.dart';
import 'package:whale/pages/means/model/means_model.dart';

import '../../../helper/component/component.dart';
import '../../means/main/widgets/select.dart';
import 'logic.dart';

class MyUploadPage extends StatelessWidget {
  MyUploadPage({Key? key}) : super(key: key);

  final logic = Get.put(My_uploadLogic());
  final state = Get.find<My_uploadLogic>().state;

  var reportType = ['', '政策措施', '招标采购'];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: detailAppBar(context, title: '我的上传'),
      backgroundColor: Color(0xffF4F6FA),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Color(0xff025DF4),
        onPressed: () => logic.showBottom(),
        child: const Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
      body: GetBuilder<My_uploadLogic>(
        builder: (logic) {
          return Column(
            children: [
              BrnTabBar(
                tabs: state.titles.map((e) => BadgeTab(text: e)).toList(),
                controller: state.tabCtrl,
                onTap: (state, index) =>
                    logic.getList(reportType: reportType[index]),
              ),
              Expanded(
                  child: state.docs.isNotEmpty
                      ? ListView.builder(
                          itemBuilder: (context, index) {
                            return Container(
                              color: Colors.white,
                              padding: EdgeInsets.all(15.r),
                              margin: EdgeInsets.symmetric(vertical: 5.r),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Image.asset(
                                    state.imgs[state.docs[index].fileType] ??
                                        'erb.webp'.imgPathMe,
                                    width: 34.r,
                                    height: 39.r,
                                  ),
                                  SizedBox(
                                    width: 10.r,
                                  ),
                                  Expanded(
                                      child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Text(
                                        state.docs[index].fileName ?? '',
                                        style: TextStyle(
                                            color: ColorsUtil.title,
                                            fontSize: 14.r),
                                        maxLines: 2,
                                      ),
                                      SizedBox(
                                        height: 5.r,
                                      ),
                                      Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(
                                            '提交时间: ${state.docs[index].createTime!.substring(0, 10)}',
                                            style: TextStyle(
                                                color: ColorsUtil.content,
                                                fontSize: 12.r),
                                            maxLines: 1,
                                          ),
                                          Text(
                                            state.statusStr[state
                                                    .docs[index].parseStatus] ??
                                                '',
                                            style: TextStyle(
                                                color: state.statusColor[state
                                                    .docs[index].parseStatus],
                                                fontSize: 12.r),
                                            maxLines: 1,
                                          ),
                                          Visibility(
                                            visible:
                                                state.docs[index].parseStatus !=
                                                    '0',
                                            child: Container(
                                              width: 65.r,
                                              height: 25.r,
                                              margin:
                                                  EdgeInsets.only(left: 10.r),
                                              decoration: BoxDecoration(
                                                  color: Color(0xff025DF4),
                                                  borderRadius:
                                                      BorderRadius.circular(
                                                          2.r)),
                                              child: Center(
                                                child: Row(
                                                  mainAxisAlignment:
                                                      MainAxisAlignment.center,
                                                  children: [
                                                    Image.asset(
                                                        state.docs[index]
                                                                    .parseStatus ==
                                                                '1'
                                                            ? 'icon_see.png'
                                                                .imgPathMe
                                                            : state.docs[index]
                                                                        .parseStatus ==
                                                                    '2'
                                                                ? 'icon_refrsh.png'
                                                                    .imgPathMe
                                                                : '',
                                                        width: 14.r,
                                                        height: 14.r),
                                                    SizedBox(
                                                      width: 5.r,
                                                    ),
                                                    GestureDetector(
                                                      onTap: () => Get.toNamed(
                                                          RouterPath
                                                              .means_detail,
                                                          arguments: MeansModel(
                                                              id: state
                                                                  .docs[index]
                                                                  .documentId,
                                                              reportType: state
                                                                  .docs[index]
                                                                  .reportType)),
                                                      child: Text(
                                                        state.docs[index]
                                                                    .parseStatus ==
                                                                '1'
                                                            ? '查看'
                                                            : state.docs[index]
                                                                        .parseStatus ==
                                                                    '2'
                                                                ? '刷新'
                                                                : '',
                                                        style: TextStyle(
                                                            color: Colors.white,
                                                            fontSize: 12.r),
                                                      ),
                                                    )
                                                  ],
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      )
                                    ],
                                  )),
                                ],
                              ),
                            );
                          },
                          itemCount: state.docs.length,
                        )
                      : noDataView())
            ],
          );
        },
      ),
    );
  }
}
